package com.hulk.rpc.registry.impl.local;

import com.hulk.rpc.config.common.HostPort;
import com.hulk.rpc.registry.ServerMetaInfo;
import com.hulk.rpc.registry.ServerRegistry;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 基于内存的服务注册中心
 *
 * @author xuxukang
 * @date 2019-03-10 10:48
 */
@Slf4j
public class LocalRegistry implements ServerRegistry {

  private static final AtomicInteger indexer = new AtomicInteger(0);
  private final String name = LocalRegistry.class.getSimpleName() + "-" + indexer.getAndIncrement();

  @Override
  public void init(List<HostPort> hostPorts) {
    if (log.isInfoEnabled()) {
      log.info("【info】{}【name】{}【hostPorts】{}", "初始化服务注册器", name, hostPorts);
    }
  }

  @Override
  public void register(ServerMetaInfo serverMetaInfo) {
    if (log.isInfoEnabled()) {
      log.info("【info】{}【name】{}【serverMetaInfo】{}", "注册服务", name, serverMetaInfo);
    }
  }

  @Override
  public void unregister(ServerMetaInfo serverMetaInfo) {
    if (log.isInfoEnabled()) {
      log.info("【info】{}【name】{}【serverMetaInfo】{}", "卸载服务", name, serverMetaInfo);
    }
  }

  @Override
  public void close() throws IOException {
    // ignore
  }
}
